package com.gzcsqic.excelapp.controller;

import com.gzcsqic.excelapp.common.R;
import com.gzcsqic.excelapp.entity.PageData;
import com.gzcsqic.excelapp.entity.Record;
import com.gzcsqic.excelapp.service.RecordService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("record")
public class RecordController {

    @Resource
    RecordService recordService;


    @PostMapping("addRecord")
    public R addRecord(Record record){
        Record r = recordService.checkRecordExisted(record);
        if(r != null){
            return R.error("名称已存在");
        }
        record.setCreateDate(new Date());
        recordService.addRecord(record);
        return R.success(record);
    }

    @RequestMapping("list")
    public R list(Record record,int pageNo,int size){
        Map<String, Object> data = recordService.getList(record, pageNo, size);
        return R.success(data);
    }
}
